package com.kingyea.app.market.appBaseInfo.vo;

import com.kingyea.app.market.appBaseInfo.bean.AppBaseInfo;
import com.kingyea.app.market.applicationType.bean.ApplicationType;
import com.kingyea.app.market.market.bean.Market;
import com.kingyea.app.market.publishMarket.bean.PublishMarket;
import com.kingyea.app.market.versionInfo.bean.VersionInfo;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.util.List;

/**
 * @author Mr.Lin
 * @version v1.0.0
 * @description AppBaseInfo2CreatePageInputVO 用于新增应用时的提交表单
 * 应用基本信息
 * @date Created in 2018-02-09 17:34:58
 */
public class AppBaseInfo2ListPageVO extends AppBaseInfo implements Serializable {

    /**
     * 类型
     */
    public ApplicationType applicationType;

    /**
     * 覆盖市场
     */
    public List<Market> markets;

    public List<PublishMarket> publishMarketList;

    public List<VersionInfo> currentVersionList;// 版本类型 1：web,2:ios3:android


    public String marketNames;// 只是为了兼容以前的页面逻辑
    public VersionInfo androidVersion;// 只是为了兼容以前的页面逻辑
    public VersionInfo iosVersion;// 只是为了兼容以前的页面逻辑
    public VersionInfo webVersion;// 只是为了兼容以前的页面逻辑


    @Override
    public ApplicationType getApplicationType() {
        return applicationType;
    }

    @Override
    public void setApplicationType(ApplicationType applicationType) {
        this.applicationType = applicationType;
    }

    public List<Market> getMarkets() {
        return markets;
    }

    public void setMarkets(List<Market> markets) {
        for (Market market : markets) {
            if (null != market && !StringUtils.isEmpty(market.getMarketName())) {
                setMarketNames((StringUtils.isEmpty(getMarketNames()) ? "" : getMarketNames()) + market.getMarketName() + ",");
            }
        }
        if (!StringUtils.isEmpty(getMarketNames())) {
            setMarketNames(getMarketNames().substring(0, getMarketNames().length() - 1));
        }
        this.markets = markets;
    }

    public List<PublishMarket> getPublishMarketList() {
        return publishMarketList;
    }

    public void setPublishMarketList(List<PublishMarket> publishMarketList) {
        for (PublishMarket publishMarket : publishMarketList) {
            if (null != publishMarket && publishMarket.getStatus().intValue() == 1) {
                this.setPublishFlag(1);// 只要有一个通过，设置为通过
                break;
            }
        }
        this.publishMarketList = publishMarketList;
    }

    public String getMarketNames() {
        return marketNames;
    }

    public void setMarketNames(String marketNames) {
        this.marketNames = marketNames;
    }

    public List<VersionInfo> getCurrentVersionList() {
        return currentVersionList;
    }

    public void setCurrentVersionList(List<VersionInfo> currentVersionList) {
        for (VersionInfo versionInfo : currentVersionList) {
            if (null != versionInfo)
                switch (versionInfo.getVersionType()) {
                    case 1:
                        setWebVersion(versionInfo);
                        break;
                    case 2:
                        setIosVersion(versionInfo);
                        break;
                    case 3:
                        setAndroidVersion(versionInfo);
                        break;
                }
        }
        this.currentVersionList = currentVersionList;
    }

    public VersionInfo getAndroidVersion() {
        return androidVersion;
    }

    public void setAndroidVersion(VersionInfo androidVersion) {
        this.androidVersion = androidVersion;
    }

    public VersionInfo getIosVersion() {
        return iosVersion;
    }

    public void setIosVersion(VersionInfo iosVersion) {
        this.iosVersion = iosVersion;
    }

    public VersionInfo getWebVersion() {
        return webVersion;
    }

    public void setWebVersion(VersionInfo webVersion) {
        this.webVersion = webVersion;
    }
}
